import React, { useState, useRef } from 'react';
import { Drawer, Button, message } from 'antd';
import PositionManageTable from '@/components/PositionManageTable';
import styles from './PositionManage.less';

const PositionManage = (props) => {
  const { handleClose, orgId } = props;
  const [btnLoading, setBtnLoading] = useState(false);
  const pmtRef = useRef();

  const handleSubmit = () => {
    pmtRef.current?.handleSubmit({
      callback: () => {
        message.success('操作成功');
        setBtnLoading(false);
        handleClose(true);
      },
    });
  };

  return (
    <Drawer
      title="岗位管理"
      width={600}
      visible
      onClose={handleClose}
      bodyStyle={{ paddingBottom: 80 }}
      footer={(
        <div style={{ textAlign: 'right' }}>
          <Button onClick={handleClose} style={{ marginRight: 8 }}> 取消</Button>
          <Button type="primary" onClick={handleSubmit} loading={btnLoading}>提交</Button>
        </div>
      )}
    >
      <PositionManageTable ref={pmtRef} orgId={orgId} setSubLoading={setBtnLoading} />
    </Drawer>
  );
};

export default PositionManage;
